/*
 *    Document   : CursoList
 *    Created on : 04/04/2013, 10:54:41
 *    Author     : Fiúza <rbfiuza@gmail.com>
 */

Ext.define('FC.view.CursoList', {
    extend: 'Ext.form.Panel',
    alias: 'widget.cursoList',

    requires: ['Ext.form.field.Text'],

    initComponent: function(){
        this.addEvents('create');
        Ext.apply(this, {
            activeRecord: null,
            iconCls: 'icon-user',
            frame: true,
            title: 'Curso',
            defaultType: 'textfield',
            bodyPadding: 5,
            width: 1200,
            fieldDefaults: {
                anchor: '100%',
                labelAlign: 'right'
            },
            items: [

            {
                fieldLabel: 'id',
                name: 'id',
                allowBlank: false,
                hidden:true //esconde o item no painel
            }
            ,{
                fieldLabel: 'idProjeto',
                name: 'idProjeto', 
                allowBlank: false,
                hidden:true
            }           
            ,{
                xtype: 'combo',
                name : 'curso',
                fieldLabel: 'curso',
                displayField: 'curso',
                valueField: 'curso',
                store:  Ext.create('FC.store.Curso'),
                queryMode:'remote',
                editable: false
            },{
                xtype: 'combo',
                name : 'nivel',
                fieldLabel: 'nivel',
                displayField: 'nivel',
                valueField: 'nivel',
                store:  Ext.create('FC.store.NivelCurso'),
                queryMode:'remote',
                editable: false
            }
            , {
                fieldLabel: 'Cursistas',
                name: 'qntCursista',
                allowBlank: false,
                scope: this,
                listeners: {
                    scope: this,
                    'change': function(field, newVal, oldVal){
                        if(oldVal != undefined ){
                            var qntP2 = Number(this.getForm().findField('qntPolos').getValue());
                            qntP2 = qntP2 * Number(newVal);
                            this.getForm().findField('qntVagaTotal').setValue(qntP2);   
                        }
                    }
                },
                checkChangeEvents:['change']

            }
            , {
                fieldLabel: 'Número de Polos',
                name: 'qntPolos',
                allowBlank: false,
                readOnly: true
            }
            , {
                fieldLabel: 'Carga Horaria',
                name: 'cargaHoraria',
                allowBlank: false
            }, {
                fieldLabel: 'Módulos',
                name: 'modulos',
                allowBlank: false                
            }, {
                fieldLabel: 'Duração em Meses',
                name: 'qntMeses',
                allowBlank: false
            }, {
                fieldLabel: 'Vagas Total',
                name: 'qntVagaTotal',
                readOnly: true
            }, 
            {
                xtype: 'fieldset',
                title: 'Polos',
                collapsible: true,
                defaults: {
                    labelWidth: 89,
                    anchor: '100%',
                    layout: {
                        type: 'hbox',
                        defaultMargins: {
                            top: 0, 
                            right: 5, 
                            bottom: 0, 
                            left: 0
                        }
                    }
                },
                items: [
                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    {
                        xtype: 'checkboxfield',
                        id: '1',
                        name:'1',
                        boxLabel: 'Águas Lindas de Goiás - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    },{
                        xtype: 'checkboxfield',
                        id: '2',
                        name:'2',
                        boxLabel: 'Alexânia - Polo UAB',
                        checked: false,
                        margin: '0 87 0 20',
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }
                    ,
                    {
                        xtype: 'checkboxfield',
                        id: '3',
                        name:'3',
                        boxLabel: 'Alto Paraiso de Goiás - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                },
                    

                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    
                    {
                        xtype: 'checkboxfield',
                        id: '4',
                        name:'4',
                        boxLabel: 'Anápolis - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    },
                    {
                        xtype: 'checkboxfield',
                        id: '5',
                        name:'5',
                        boxLabel: 'Aparecida de Goiânia - Polo UAB',
                        margin: '0 19 0 95',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '6',
                        name:'6',
                        boxLabel: 'Catalão - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                },
                    

                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    {
                        xtype: 'checkboxfield',
                        id: '7',
                        name:'7',
                        boxLabel: 'Cezarina - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '8',
                        name:'8',
                        boxLabel: 'Formosa - Polo UAB',
                        margin: '0 87 0 95',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }
                        else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '9',
                        name:'9',
                        boxLabel: 'Goianésia - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                },
                    

                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    {
                        xtype: 'checkboxfield',
                        id: '10',
                        name:'10',
                        boxLabel: 'Inhumas',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '11',
                        name:'11',
                        boxLabel: 'Ipora - Polo UAB',
                        margin: '0 104 0 155',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '12',
                        name:'12',
                        boxLabel: 'Itumbiara - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                }, 
            
            
                    

                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    {
                        xtype: 'checkboxfield',
                        id: '13',
                        name:'13',
                        boxLabel: 'Jussara - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '14',
                        name:'14',
                        boxLabel: 'Mineiros - Polo UAB',
                        margin: '0 89 0 101',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '15',
                        name:'15',
                        boxLabel: 'Morrinhos - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                },
                    
                    

                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    , {
                        xtype: 'checkboxfield',
                        id: '16',
                        name:'16',
                        boxLabel: 'Piranhas - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '17',
                        name:'17',
                        boxLabel: 'Posse - Polo UAB',
                        margin: '0 101 0 95',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '18',
                        name:'18',
                        boxLabel: 'Rio Verde - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                }, 
            

                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    {
                        xtype: 'checkboxfield',
                        id: '19',
                        name:'19',
                        boxLabel: 'São Miguel do Araguaia - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '20',
                        name:'20',
                        boxLabel: 'São Simão - Polo UAB',
                        margin: '0 76 0 13',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '21',
                        name:'21',
                        boxLabel: 'Uruaçu - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                },
            

                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '',
                    combineErrors: true,
                    msgTarget: 'under',
                    defaults: {
                        hideLabel: true
                    },
                    items: [
                    {
                        xtype: 'checkboxfield',
                        id: '22',
                        name:'22',
                        boxLabel: 'Uruana - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '23',
                        name:'23',
                        boxLabel: 'Vila Boa de Goiás - Polo UAB',
                        margin: '0 40 0 101',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }, {
                        xtype: 'checkboxfield',
                        id: '24',
                        name:'24',
                        boxLabel: 'Votuporanga SP - Polo UAB',
                        checked: false,
                        scope: this,
                        handler: function (field, value) {
                            scope: this,
                            this.checkValue = field.getValue();
                        var qntP;
                        var qntC; 
                        var qntVt;
                            
                        if(this.checkValue == true){
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            qntP = qntP + 1;
                            qntVt = qntP * qntC;
                                
                            this.getForm().findField('qntVagaTotal').setValue(qntVt);
                            this.getForm().findField('qntPolos').setValue(qntP); 
                        }else{
                                
                            qntP = Number(this.getForm().findField('qntPolos').getValue());
                            qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
                            if(qntP > 0){
                                qntP = qntP - 1;
                                qntVt = qntP * qntC;
                                    
                                this.getForm().findField('qntVagaTotal').setValue(qntVt);
                                this.getForm().findField('qntPolos').setValue(qntP);    
                            }
                        }
                        }
                    }]
                }

                ]
            }],
            dockedItems: [{
                xtype: 'toolbar',
                dock: 'bottom',
                ui: 'footer',
                items: ['->', {
                    iconCls: 'icon-save',
                    itemId: 'savar',
                    text: 'Savar',
                    disabled: true,
                    scope: this
                    ,
                    handler: this.onSave
                }, {
                    iconCls: 'icon-add',
                    text: 'Criar',
                    scope: this
                    ,
                    handler: this.onCreate
                }, {
                    iconCls: 'icon-reset',
                    text: 'Limpar',
                    scope: this
                    ,
                    handler: this.onReset
                }]
            }]

        });
        this.callParent();
    },

    onCreate: function(){

//                this.getForm().set FC.model.Global.idProjeto
                this.getForm().findField('idProjeto').setValue(FC.model.Global.idProjeto);
                this.fireEvent('create', this, this.getForm().getValues());

    },
    onSave: function(){

        console.log('passou save!');
        this.getForm().submit({
            url: 'atualizaCursoProjeto'
            ,
            success: function(form, action) {
                Ext.Msg.alert('Salvo com Sucesso', action.result.message);
                           
                var element = Ext.getCmp('cursosProjetoList');
                
                element.getStore().load({
                    params: {
                        idprojeto: FC.model.Global.idProjeto
                    }
                });

                form.reset();
                           
            }
            ,
            failure: function(form, action) {
                Ext.Msg.alert('Falha ao atualizar', action.result ? action.result.message : 'Não responde ao atualizar');
            }
        });

    },
    
    onReset: function(){
        this.getForm().reset();
        
        var button = this.getForm().owner.query('button[text=Savar]');
        button[0].disable();

    },
    
    onChangeFormulario: function(field, value){
        
        scope: this,
        this.checkValue = field.getValue();
    var qntP;
    var qntC; 
    var qntVt;
                            
    if(this.checkValue == true){
                                
        qntP = Number(this.getForm().findField('qntPolos').getValue());
        qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
        qntP = qntP + 1;
        qntVt = qntP * qntC;
                                
        this.getForm().findField('qntVagaTotal').setValue(qntVt);
        this.getForm().findField('qntPolos').setValue(qntP); 
    }else{
                                
        qntP = Number(this.getForm().findField('qntPolos').getValue());
        qntC = Number(this.getForm().findField('qntCursista').getValue());
                                
        if(qntP > 0){
            qntP = qntP - 1;
            qntVt = qntP * qntC;
                                    
            this.getForm().findField('qntVagaTotal').setValue(qntVt);
            this.getForm().findField('qntPolos').setValue(qntP);    
        }
    }
    }
}); 